package com.dylan.job.entity;

import com.dylan.job.consts.RespCode;
import com.dylan.job.consts.RespMsg;
import lombok.Data;

import java.io.Serializable;

/**
 * @author dylan
 * @description 返回参数封装
 * @date 2025/2/12  21:53
 */
@Data
public class RespEntity<T> implements Serializable {

    private Integer code;

    private String msg;

    private T data;

    public static <T> RespEntity<T> success(T data) {
        RespEntity resp = new RespEntity();
        resp.setCode(RespCode.SUCCESS);
        resp.setMsg(RespMsg.SUCCESS);
        resp.setData(data);
        return resp;
    }


    public static <T> RespEntity<T> success() {
        RespEntity resp = new RespEntity();
        resp.setCode(RespCode.SUCCESS);
        resp.setMsg(RespMsg.SUCCESS);
        return resp;
    }

    public static <T> RespEntity<T> error(String msg) {
        RespEntity resp = new RespEntity();
        resp.setCode(RespCode.SYSTEM_ERROR);
        resp.setMsg(msg);
        return resp;
    }

    public static <T> RespEntity<T> error(Integer code, String msg) {
        RespEntity resp = new RespEntity();
        resp.setCode(code);
        resp.setMsg(msg);
        return resp;
    }
}
